package com.example.kaiya;

import java.io.IOException;
import java.io.InputStream;
import java.util.Timer;
import java.util.TimerTask;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.res.AssetManager;
import android.util.Log;
import android.view.Menu;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import android.widget.LinearLayout;

public class SplashActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);
		
		if(M.m.picket == -1){
			AssetManager am = getResources().getAssets();
			InputStream is = null;
			try {
				is = am.open("database.csv");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				//System.exit(0);
			}
			M.m.Load(is);
			M.m.printLog();
			M.m.picket = 0;
		}
		
		Animation fade = AnimationUtils.loadAnimation(this, R.anim.fade_out);
		LayoutAnimationController controller = new LayoutAnimationController(fade);
		LinearLayout splashV = (LinearLayout) findViewById(R.id.splashView);
		splashV.setLayoutAnimation(controller);
		fade.setAnimationListener(new AnimationListener(){
			public void onAnimationEnd(Animation animation){
				startActivity(new Intent(SplashActivity.this, MainActivity.class));
				SplashActivity.this.finish();
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub
				
			}
		});
		//startActivity(new Intent(SplashActivity.this, MainActivity.class));
		//SplashActivity.this.finish();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
